const { CHANGE_AGE, CHANGE_NAME } = require("../store/constants")
const initStore = {
  name: "Kobe",
  age: 18
}
// reducer是还原器的英文，很有意思的取名
const reducer = (state = initStore, action) => {
  switch (action.type) {
    case CHANGE_NAME:
      return { ...state, name: action.name }
    case CHANGE_AGE:
      return { ...state, age: action.age + state.age }
  }
  return state // 这是因为一开始要直接返回的initState
}

module.exports = reducer
